/**
 * Created by zhourh on 2018/7/27.
 * 给定一个矩阵 A， 返回 A 的转置矩阵。

 矩阵的转置是指将矩阵的主对角线翻转，交换矩阵的行索引与列索引。
 *
 */
public class TransposeMatrix {

    public int[][] transpose(int[][] A) {
        if (A == null || A.length == 0 || A[0].length == 0) {
            return A;
        }

        int[][] result = new int[A[0].length][A.length];
        int height = result.length;
        int width = result[0].length;

        for (int row = 0; row < height; row++) {
            for (int column = 0; column < width; column++) {
                result[row][column] = A[column][row];
            }
        }

        return result;
    }
}
